// pages/myLawyers/myLawyers.js
import hanziToPinyin from "../../utils/hanziToPinyin.js";
import formatDate from '../../utils/util.js';
import request from '../../utils/config.js';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    ossImgUrL: 'https://winhc.oss-cn-shanghai.aliyuncs.com/xcx/',
    parentList:new Array(),
    bussinessInfoList: new Array(),
    showLawyerList:true
  },

  /**
 * 生命周期函数--监听页面初次渲染完成
 */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  goIndex: function (e) {
    let openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '../card/otherIndex/otherIndex?openid=' + openid
    })
  },

  goCall: function (e) {
    var iPhone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: iPhone
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getLawyerList();
  },

  //获取律师列表
  getLawyerList: function(){
    wx.showLoading({
      title: '加载中',
    })
    let headerInfo = {
      pageNum: "1000",
      pageSize: "",
      sessionId: app.globalData.sessionId,
    }
    let bodyInfo = {
      openid: app.globalData.openid
    }
    let _that = this;
    request.requestLogin_api("queryUserLawyerRelate", headerInfo, bodyInfo, (data) => {
      console.log("查询用户关联律师信息成功", data)
      let bodyInfo = JSON.parse(data.data.body).lawyerList;
      if (bodyInfo.length > 0){
        // let tempArray = new Array();
        bodyInfo.forEach(function (e) {
          if (e.openid) {
            if (!e.userName) {
              e.userName = e.nickName ? e.nickName : "暂无";
            }
            if (!e.lawfirmName) {
              e.lawfirmName = "暂无";
            }
            if (!e.avatarUrl) {
              e.avatarUrl = "../../img/logo.png"
            }
          }
        });
        _that.setData({
          parentList: bodyInfo
        });
      }else{
        _that.setData({
          showLawyerList: false
        })
      }
      setTimeout(function(){
        wx.hideLoading()
      },300);
      wx.stopPullDownRefresh();
    }, (data) => {
      setTimeout(function () {
        wx.hideLoading()
      }, 300);
      console.log("查询用户关联律师信息失败", data)
      wx.showModal({
        title: "加载失败",
        content: '请尝试下拉界面重新加载',
        confirmText: '确定',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
          } else if (res.cancel) {
          }
        }
      })
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getLawyerList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
})